import React, { PureComponent } from 'react';
import { message, Form, Input } from 'antd';
import { connect } from 'dva';
import SyOrderTableComponent from '../../components/SyOrderTableComponent';
import moment from 'moment';
import { getAuthority, setAuthority } from '../../utils/authority';
import styles from '../../components/SyOrderTableComponent/index.less';

const FormItem = Form.Item;
const { TextArea } = Input;

@Form.create()
@connect(state => ({
  modelState: state.systemUser,
}))
export default class SystemUser extends SyOrderTableComponent {

  // 缺省
  _initSortion = { sortField: 'id', sortOrder: 'desc', };
  _initPagination = { pageSize: 10, current: 1, };
  _initCriteriaQuery = {};
  _operator = [
  ];

  initSelection() {
    const { dispatch } = this.props;
    dispatch({
      type: 'systemUser/fetchSelectItems',
      payload: { service: '/user', apiUrl: '/system/organization', selectName: 'systemOrganizationSelectItems' }
    });
    dispatch({
      type: 'systemUser/fetchSelectItems',
      payload: { service: '/user', apiUrl: '/system/role', selectName: 'systemRoleSelectItems' }
    });
  }


  componentWillMount() {
    this.initSelection();
    this.setState({
      baseModel: 'systemUser',
      operator: this._operator,
      needSearch: true,
      needAdd: true,
      needEdit: true,
      needDelete: true,
      needTableColumnsOperator: true,
      // addAuth: 'system:user:add',
      // editAuth: 'system:user:edit',
      // deleteAuth: 'system:user:delete',
      needTableCheckbox: true,
      tableBorder: true,
      tableScroll: { y: 800 },
      tableColumns: [
        {
          title: '姓名',
          dataIndex: 'name',
          width: 180,
          sorter: true,
        },
        {
          title: '用户名',
          dataIndex: 'userName',
          width: 180,
          sorter: true,
        },
        {
          title: '所属部门',
          dataIndex: 'organization.organizationName',
          width: 180,
          sorter: true,
        },
        {
          title: '主角色',
          dataIndex: 'primaryRole.roleName',
          width: 180,
        },
        {
          title: '备注',
          dataIndex: 'remark',
          width: 240,
          type: 'longString',
          // style: { padding: '0px' },
          // className: styles.nopadding,
          // render: (text, record) => <TextArea value={record.remark} ></TextArea>
        },
        {
          title: '创建人',
          dataIndex: 'createUser.name',
          width: 140,
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          // width: 180,
        },
      ],
      searchFormItem: [
        {
          name: 'userName',
          label: '用户名',
          placeholder: '用户名',
          type: 'string',
          selectOption: [{ name: '', value: '' }],
        },
        {
          name: 'name',
          label: '姓名',
          placeholder: '姓名',
          type: 'string',
          selectOption: [{ name: '', value: '' }],
        },
        {
          name: 'organization',
          label: '所属部门',
          placeholder: '所属部门',
          type: 'select',
          selectOption: { itemName: 'systemOrganizationSelectItems', name: 'organizationName', value: 'id', },
        },
      ],
      simpleAddFormItem: [
        {
          name: 'userName',
          label: '用户名',
          placeholder: '用户名',
          type: 'string',
          selectOption: [{ name: '', value: '' }],
          rules: [{
            required: true, message: '请输入用户名',
          }],
        },
        {
          name: 'name',
          label: '姓名',
          placeholder: '姓名',
          type: 'string',
          selectOption: [{ name: '', value: '' }],
          rules: [{
            required: true, message: '请输入姓名',
          }],
        },
        {
          name: 'primaryRoleId',
          label: '角色',
          placeholder: '角色',
          type: 'select',
          selectOption: { itemName: 'systemRoleSelectItems', name: 'roleName', value: 'id' },
          // rules: [{
          //   required: true, message: '请选择角色',
          // }],
        },
        {
          name: 'organizationId',
          label: '所属部门',
          placeholder: '所属部门',
          type: 'select',
          selectOption: { itemName: 'systemOrganizationSelectItems', name: 'organizationName', value: 'id' },
          // rules: [{
          //   required: true, message: '请选择部门',
          // }],
        },
        {
          name: 'remark',
          label: '备注',
          placeholder: '备注',
          type: 'longString',
          selectOption: [{ name: '', value: '' }],
        },
      ],
      simpleEditFormItem: [
        {
          name: 'userName',
          label: '用户名',
          placeholder: '用户名',
          type: 'string',
          selectOption: [{ name: '', value: '' }],
          rules: [{
            required: true, message: '请输入用户名',
          }],
        },
        {
          name: 'name',
          label: '姓名',
          placeholder: '姓名',
          type: 'string',
          selectOption: [{ name: '', value: '' }],
          rules: [{
            required: true, message: '请输入姓名',
          },],
        },
        {
          name: 'primaryRoleId',
          label: '角色',
          placeholder: '角色',
          type: 'select',
          selectOption: { itemName: 'systemRoleSelectItems', name: 'roleName', value: 'id' },
          rules: [{
            required: true, message: '请选择角色',
          }],
        },
        {
          name: 'organizationId',
          label: '所属部门',
          placeholder: '所属部门',
          type: 'select',
          selectOption: { itemName: 'systemOrganizationSelectItems', name: 'organizationName', value: 'id' },
          rules: [{
            required: true, message: '请选择部门',
          }],
        },
        {
          name: 'remark',
          label: '备注',
          placeholder: '备注',
          type: 'longString',
          selectOption: [{ name: '', value: '' }],
        },
      ],
    });
  }

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    super.componentDidMount();
  }

}
